package com.google.samples.apps.databinging

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.databinding.DataBindingUtil
import com.google.samples.apps.databinging.binding.Book
import com.google.samples.apps.databinging.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {
    var book: Book? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
//        setContentView(R.layout.activity_main)
        val binding =
            DataBindingUtil.setContentView<ActivityMainBinding>(this, R.layout.activity_main)

        book = Book("Android Jetpack应用指南", "佚名", 0)

        binding.setVariable(BR.book, book)
        binding.setVariable(BR.click, Click())
        binding.imgUrl = "https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1602568647&di=aadbe1fd48cea0cb28b39f0b56f7ec85&src=http://pic4.zhimg.com/v2-43a5bd47255dbb648237836642b4f233_b.jpg"
        binding.imgRes = R.drawable.ic_launcher_background
//        tvTitle.text = book.title
//        tvAuthor.text = book.author
//        tvRating.text = "${book.rating}"

    }


    inner class Click {
        fun onClickMe(view: View) {
            Toast.makeText(view.context, "click me", Toast.LENGTH_SHORT).show()
            book?.let {
                it.rating = it.rating + 1
            }
        }
    }
}